    <%--
  Created by IntelliJ IDEA.
  User: liuxi
  Date: 2018/5/25
  Time: 14:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>日程管理</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/bootstrap/css/bootstrap.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/table/bootstrap-table.min.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/date/bootstrap-datetimepicker.min.css"/>
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/statics/sweetalert.css"/>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/statics/sweetalert.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/jquery-3.2.1.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/statics/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/statics/table/bootstrap-table.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/statics/table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/date/Moment.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/statics/date/bootstrap-datetimepicker.min.js"></script>
</head>
<body>
<div class="panel panel-default">
    <div class="panel-body">
        <form class="form-inline">
            <div class="form-group">
                姓名：<input id="nName" name="nId" type="text" class="form-control" placeholder="搜索内容">
            </div>
            日期:
            <div class="input-group input-daterange">
                <input id="startTime" type="text" class="form-control">
                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
                <div class="input-group-addon">到：</div>
                <input id="endTime" type="text" class="form-control">
                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
            </div>
            <button onclick="search()" type="button" class="btn btn-default">查询</button>
        </form>
    </div>
</div>
<div>
    <!-- Nav tabs -->
    <ul class="nav nav-tabs" role="tablist">
        <li role="presentation" class="active"><a class="home" href="#home" aria-controls="home" role="tab"
                                                  onclick="TabTable(1)" data-toggle="tab">当天日程</a></li>
        <li role="presentation"><a href="#profile" class="profile" aria-controls="profile" role="tab"
                                   onclick="TabTable(2)" data-toggle="tab">明天日程</a></li>
        <li role="presentation"><a href="#messages" class="messages" aria-controls="messages" role="tab"
                                   onclick="TabTable(3)" data-toggle="tab">下周日程</a></li>
        <li role="presentation"><a href="#settings" class="settings" aria-controls="settings" role="tab"
                                   onclick="TabTable(4)" data-toggle="tab">所有日程</a></li>
    </ul>

    <!-- Tab panes -->
    <div class="tab-content">
        <div role="tabpanel" class="tab-pane active" id="home">
            <table id="table" class="table"></table>
        </div>
        <div role="tabpanel" class="tab-pane" id="profile">
            <table id="table1" class="table"></table>
        </div>
        <div role="tabpanel" class="tab-pane" id="messages">
            <table id="table2" class="table"></table>
        </div>
        <div role="tabpanel" class="tab-pane" id="settings">
            <table id="table3" class="table"></table>
        </div>
    </div>
</div>
<input type="text" style="display: none" value="1" id="tabInput">
<%--模态框--%>
<div  id="myModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form>
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">日程修改</h4>
                </div>
                <div class="modal-body">
                    <p>日程编号：<input type="text" name="scheduleid"></p>
                </div>
                <div class="modal-body">
                    <p>开始时间：<input type="text" name="scheduleid"></p>
                </div>
                <div class="modal-body">
                    <p>结束时间：<input type="text" name="scheduleid"></p>
                </div>
                <div class="modal-body">
                    <p>就诊医生：
                        <select name="nId">
                            <option></option>
                        </select>
                    </p>
                </div>
                <div class="modal-body">
                    <p>就诊项目：<input type="text" name="scheduleMatter"></p>
                </div>
                <div class="modal-body">
                    <p>状态：<input type="text" name="state"></p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Save changes</button>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

</body>
<script type="text/javascript">

    function TabTable(id) {
        $("#tabInput").val(id);
    }

    function queryParams(params) {
        var nId = ${sessionScope.nurse.nId};
        var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
            pageSize: params.pageSize,  //页面大小
            pageNumber: params.pageNumber, //页码
            nName: $("#nName").val(),
            starTime: $("#startTime").val(),
            endTime: $("#endTime").val(),
            tabinput: $("#tabInput").val(),
            nId:nId
        };
        return temp;
    }

    function search() {
        var opts = $("#table").bootstrapTable('getOptions');
        var nName = $("#nName").val();
        var startTime = $("#startTime").val();
        var endTime = $("#endTime").val();
        var tabinput = $("#tabInput").val();
        var nId = ${nurse.nId};
        $.ajax({
            "url": "${pageContext.request.contextPath}/schedule/getToDay",
            "type": "post",
            "data": {
                "nName": nName,
                "starTime": startTime,
                'endTime': endTime,
                "pageNumber": opts.pageNumber,
                "pageSize": opts.pageSize,
                "tabinput": tabinput,
                "nId":nId
            },
            "dataType": "json",
            "success": function (data) {
                $(".table").bootstrapTable('load', data);
            }
        })
    }


    window.operateEvents = {
        "click .del": function (e, value, row, index) {
            swal({
                title: "您确定要删除这条信息吗",
                text: "删除后将无法恢复，请谨慎操作！",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "删除",
                closeOnConfirm: true
            }, function () {
                $.ajax({
                    "url": '${pageContext.request.contextPath}/schedule/del',
                    "type": "post",
                    "data": {"scheduleid": row.scheduleid},
                    "dataType": "json",
                    "success": function (data) {
                        if (data >= 1) {
                            $(".table").bootstrapTable('refresh');
                        }
                    }
                })
            });
        }, "click .toadd": function (e, value, row, index) {
            var tabinput = $("#tabInput").val();
            if(tabinput==1&&row.state == 1){
                var starTime = row.starTime;
                var endTime = row.endTime;
                var nid = ${nurse.nId};
                $.ajax({
                    "url":'${pageContext.request.contextPath}/case/toAddCase',
                    "data":{"starTime":starTime,"endTime":endTime,"nId":nid},
                    "type":"post",
                    "dataType":"json",
                    "success":function(data){
                        location.href = "${pageContext.request.contextPath}/case/toCase?data="+data;
                    }
                })
            }
        }
    };
    $(".home").bind("click", function () {
        $(".table").empty();
        search();
    });
    $(".profile").bind("click", function () {
        search();
    });
    $(".messages").bind("click", function () {
        search();
    });
    $(".settings").bind("click", function () {
        $(".table").empty();
        search();
    });

    $(function () {
        // 时间插件
        $('#startTime').datetimepicker({
            //viewMode: 'day',
            format: 'YYYY-MM-DD'
        });
        $('#endTime').datetimepicker({
            format: 'YYYY-MM-DD',
            useCurrent: false //Important! See issue #1075
        });
        $("#startTime").on("dp.change", function (e) {
            $('#endTime').data("DateTimePicker").minDate(e.date);
        });
        $("#endTime").on("dp.change", function (e) {
            $('#startTime').data("DateTimePicker").maxDate(e.date);
        });
        //bootstrapTable
        $(".table").bootstrapTable({
            url: '${pageContext.request.contextPath}/schedule/getToDay',
        /*    onDblClickRow:function(row,$element){
                var id=row.pId;
                $.ajax({
                    url:"${pageContext.request.contextPath}/schedule/AddCase",
                    type:"post",
                    data:{"id":id},
                    success:function (data) {

                    }
                })
            },*/
            columns: [{
                title: '时间段',
                formatter: function (index, row, value) {
                    var tabinput = $("#tabInput").val();
                    var str = row.starTime;
                    if (tabinput == 1 || tabinput == 2) {
                        var r = row.starTime.substring(11, 16);
                        var r1 = row.endTime.substring(11, 16);
                        return "&nbsp;" + r + " ～" + r1;
                    } else if (tabinput == 3) {
                        var weekDay = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
                        var myDate = new Date(Date.parse(str.replace(/-/g, "/")));
                        var r = row.starTime.substring(5, 7);
                        var a = row.starTime.substring(7, 10);
                        var b = row.starTime.substring(11, 16);
                        var r1 = row.endTime.substring(10, 16);
                        return "&nbsp;" + r + "月" + a + "日 " +"下"+ weekDay[myDate.getDay()]+ "&nbsp;" +b + " ～" + r1;
                    } else {
                        var r = row.starTime.substring(0, 7);
                        var a = row.starTime.substring(7, 10);
                        var b = row.starTime.substring(11, 16);
                        var r1 = row.endTime.substring(10, 16);
                        return "&nbsp;" + r + "月" + a + "日 " + b + " ～" + r1;
                    }
                }
            }, {
                field: 'nName',
                title: '医师'
            }, {
                field: 'scheduleMatter',
                title: '日程事项'
            }, {
                title: '状态',
                formatter: function (index, row, value) {
                    if (row.state == 0) {
                        return "未预约"
                    } else if (row.state == 1) {
                        return "已预约"
                    } else if (row.state == 2) {
                        return "进行中"
                    }else if(row.state == 3){
                        return "已完成"
                    }else if(row.state == 4){
                        return "失约"
                    }
                }
            }, {
                title: '操作',
                events: operateEvents,
                formatter: caozuo
            }],
            onDblClickCell: function (field, $element, row) {

            },
            method: 'post',
            contentType: "application/x-www-form-urlencoded",
            height: 500,
            pageList: [5, 10, 15],
            pageSize: 5,
            sortable: true,
            sortOrder: "asc",
            pageNumber: 1,
            pagination: true,
            queryParamsType: '',
            queryParams: queryParams,
            sidePagination: 'server'
        });
        function caozuo(value, row, index) {
            var tabinput = $("#tabInput").val();
            if(tabinput==1){
                return [
                    "<a class='del' href=javascript:del(" + row.scheduleid + ")>删除</a>&nbsp;&nbsp;<a class='toadd' href=javascript:toadd(" + row.scheduleid + ")>添加病历</a>"
                ].join("");
            }else{
                return [
                    "<a class='del' href=javascript:del(" + row.scheduleid + ")>删除</a>"
                ].join("");
            }
        }
    });
</script>
</html>
